<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动画版下拉菜单</title>
    <script src="js/jquery-3.2.1.min.js"></script>
    <style>
        * {
      margin: 0;
      padding: 0;
    }

    ul {
      list-style: none;
    }

    .wrap {
      width: 330px;
      height: 30px;
      margin: 100px auto 0;
      padding-left: 10px;
      background-image: url(images/bg.jpg);
    }

    .wrap li {
      background-image: url(images/libg.jpg);
    }

    .wrap>ul>li {
      float: left;
      margin-right: 10px;
      position: relative;
    }

    .wrap a {
      display: block;
      height: 30px;
      width: 100px;
      text-decoration: none;
      color: #000;
      line-height: 30px;
      text-align: center;
    }

    .wrap span {
      display: block;
      height: 30px;
      width: 100px;
      text-decoration: none;
      color: #000;
      line-height: 30px;
      text-align: center;
    }

    .wrap li ul {
      position: absolute;
      top: 30px;
      display: none;
    }
  </style>
    </style>
</head>
<body>
    <div class="wrap">
        <ul>
          <li>
            <a href="javascript:void(0);">一级菜单1</a>
            <!-- <a href="javascript:void(0);">一级菜单1</a> -->
            <ul>
              <li><a href="javascript:void(0);">二级菜单1</a></li>
              <li><a href="javascript:void(0);">二级菜单2</a></li>
              <li><a href="javascript:void(0);">二级菜单3</a></li>
            </ul>
          </li>
          <li>
            <a href="javascript:void(0);">一级菜单1</a>
            <ul>
              <li><a href="javascript:void(0);">二级菜单1</a></li>
              <li><a href="javascript:void(0);">二级菜单2</a></li>
              <li><a href="javascript:void(0);">二级菜单3</a></li>
            </ul>
          </li>
          <li>
            <a href="javascript:void(0);">一级菜单1</a>
            <ul>
              <li><a href="javascript:void(0);">二级菜单1</a></li>
              <li><a href="javascript:void(0);">二级菜单2</a></li>
              <li><a href="javascript:void(0);">二级菜单3</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </body>
<script>
    /**
        动画下拉菜单是在下拉菜单功能的基础之上添加的上拉和下拉动画效果，
        主要的实现思路是给一级菜单的li标签设置鼠标移入事件，二级菜单ul显示。
        给一级菜单li设置鼠标离开事件，二级菜单隐藏。
    */
    /**
        a)	获取ul下的li元素
        b)	注册鼠标移入事件，实现鼠标移入下拉动画效果
        c)	鼠标移出事件，实现鼠标移出上拉动画效果
    */
    $(function(){
        $('.wrap>ul>li').mouseenter(function(){
            $(this).children('ul').stop().slideDown(300);
        });
        $('.wrap>ul>li').mouseleave(function(){
            $(this).find('ul').stop().slideUp(50);
        });
    });
</script>
</html>